<template>
  <div class="barcode-entry-container">
    <div class="title-label">课程名称：{{ courseName }}</div>
    <div>
      <el-row>
        <el-col :span="12" class="left-container">
          <div>
            <span>总人数：<span class="red-number">{{ totalNum }}</span></span>
            <span>已录：<span class="red-number">{{ enteredNum }}</span></span>
          </div>
          <div class="barcode-container">
            <span>条形码</span>
            <div style="border: none;">
              <el-input ref="studentNo" v-model="studentNo" type="password" @change="handleChange" />
            </div>
          </div>
          <div class="achievement-container">
            <span>成绩</span>
            <div style="border: none;">
              <el-input ref="score" v-model="score" @keyup.enter.native="handleUpdate" />
            </div>
          </div>
        </el-col>
        <el-col :span="12" class="right-container">
          <el-table
            border
            :data="tableData"
            :height="490"
            class="xpaas-table-class"
            row-class-name="xpaas-row-class"
            cell-class-name="xpaas-cell-class"
            header-row-class-name="xpaas-header-row-class"
            header-cell-class-name="xpaas-header-cell-class">
            <el-table-column type="index" label="序号" width="100" align="center" />
            <el-table-column prop="issue" label="成绩" align="center" />
          </el-table>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import { queryList, updateScore, queryScoreList } from '@/api/courseAchievement/manualEntry'
export default {
  name: "barcodeEntry",
  data() {
    return {
      courseName: '【165161】博士课博士学位论文写作导读（必修）',
      totalNum: 0,
      enteredNum: 0,
      studentNo: '',
      score: '',
      tableData: [],
      planId: this.$route.query.planId
    }
  },
  mounted () {
    this.$refs.studentNo.focus()
    if (this.planId === undefined || this.planId === '') {
      this.$message.error('课程信息丢失！')
    } else {
      this.handleInitCourse(this.planId)
      this.handleInitList(this.planId)
    }
  },
  methods: {
    handleInitCourse: function () {
      queryList(this.planId).then(res => {
        if (res.data.code === 200) {
          this.courseName = res.data.data.coursename
          this.totalNum = res.data.data.kzyl
          this.enteredNum = res.data.data.kznum
        }
      })
    },
    handleInitList: function (planId) {
      queryScoreList(planId).then(res => {
        if (res.data.code === 200) {
          this.tableData = res.data.data
        }
      })
    },
    handleChange: function (val) {
      if (val !== '') {
        this.$refs.score.focus()
      } else {
        this.$refs.studentNo.focus()
      }
    },
    handleUpdate: function () {
      if (this.studentNo !== '' && this.score !== '') {
        const params = {
          planid: this.$route.query.planId,
          studentid: this.studentNo,
          issue: this.score,
          kzkhstate: '2'
        }
        updateScore(params).then(() => {
          this.handleInitCourse(this.planId)
          this.handleInitList(this.planId)
          this.studentNo = ''
          this.score = ''
          this.$refs.studentNo.focus()
        })
      }
    }
  }
};
</script>

<style scoped lang="less">
@fontFamily:"Microsoft YaHei";
.xpaas-table-class {
  border: 1px solid #004ca7;
  border-radius: 9px;
  ::v-deep div.el-table__header-wrapper {
    table.el-table__header {
      thead {
        tr.xpaas-header-row-class {
          padding: 0;
          height: 60px;
          background-color: #edf2f9;
          font-size: 16px;
          font-family: @fontFamily;
          font-weight: bold;
          line-height: 20px;
          color: #004ca7;
          th.xpaas-header-cell-class {
            font-weight: bold;
            border-right: 1px solid #c7d7eb;
            border-left: 0;
            border-bottom: 1px solid #c7d7eb;
            background-color: #edf2f9;
            div.cell {
              font-size: 16px;
              font-weight: bold;
              font-family: @fontFamily;
              color: #004ca7;
            }
          }
        }
      }
    }
  }
  ::v-deep div.el-table__body-wrapper {
    table.el-table__body {
      tbody {
        tr.xpaas-row-class {
          td.xpaas-header-cell-class {
            border-right: 1px solid #c7d7eb;
            border-left: 0;
            border-bottom: 1px solid #c7d7eb;
            background-color: #edf2f9;
            div.cell {
              font-size: 16px;
              font-weight: bold;
              font-family: @fontFamily;
              color: #004ca7;
            }
          }
          td.xpaas-cell-class {
            height: 60px;
            border-right: 1px solid #c7d7eb;
            border-left: 0;
            border-bottom: 1px solid #c7d7eb;
            div.cell {
              font-family: @fontFamily;
              color: #004ca7;
            }
          }
        }
      }
    }
  }
}
.barcode-entry-container {
  // padding-top: 46px;
  text-align: center;

  .title-label {
    font-size: 18px;
    font-weight: bold;
    line-height: 20px;
    color: #004CA7;
    margin-bottom: 26px;
  }

  > div:nth-child(2) {
    width: 100%;
    height: 669px;
    border: 1px solid rgba(0, 76, 167, 0.8);
    border-radius: 6px;
    margin: 0 auto;
    font-size: 16px;
    color: rgba(0, 76, 167, 1);

    .left-container {
      text-align: left;
      padding: 80px 0 0 166px;
      font-weight: bold;

      > div {
        &:nth-child(1) {
          > span:nth-child(1) {
            margin-right: 60px;
          }

          .red-number {
            color: rgba(255, 56, 25, 1);
          }
        }
      }

      .barcode-container {
        margin-top: 65px;

        > div {
          width: 519px;
          height: 85px;
          border: 1px solid #054CA7;
          margin-top: 14px;
        }
      }

      .achievement-container {
        margin-top: 65px;

        > div {
          width: 519px;
          height: 187px;
          border: 1px solid #054CA7;
          margin-top: 14px;
        }
      }
    }

    .right-container {
      padding: 80px 50px;

      .achievement-table {
        width: 677px;
        height: 488px;
        border: 1px solid rgba(0, 76, 167, 0.8);
        border-radius: 6px;
        list-style: none;

        li {
          border-bottom: 1px solid rgba(0, 76, 167, 0.4);

          > span {
            display: inline-block;
            height: 45px;
            text-align: center;
            line-height: 50px;

            &:nth-child(1) {
              width: 274px;
              border-right: 1px solid rgba(0, 76, 167, 0.4);
            }

            &:nth-child(2) {
              width: 401px;
            }
          }

          &:last-child {
            border-bottom: none;
          }
        }

        .active {
          height: 73px;
          background: rgba(77, 129, 192, 0.1);

          > span {
            height: 73px;
            line-height: 70px;
            font-weight: bold;
          }
        }
      }
    }
  }
}
</style>
